package com.ch.ms.server.login.service.impl;

import com.ch.ms.data.domain.ChmsServer;
import com.ch.ms.data.domain.ChmsServerType;
import com.ch.ms.dto.MapleWorldServerDto;
import com.ch.ms.server.base.configuration.motan.MotanServiceExports;
import com.ch.ms.service.ChmsServerCacheService;
import com.ch.ms.service.MapleServerManageService;
import com.weibo.api.motan.config.springsupport.annotation.MotanService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


@Service
@MotanService(export = MotanServiceExports.WORLD_SERVER_MANAGE_SERVICE)
@Slf4j
public class WorldServerManageService implements MapleServerManageService<MapleWorldServerDto> {


    private final ChmsServerCacheService chmsServerCacheService;

    @Autowired
    public WorldServerManageService(ChmsServerCacheService chmsServerCacheService) {
        this.chmsServerCacheService = chmsServerCacheService;
    }

    @Override
    public void register(MapleWorldServerDto mapleWorldServer) {

        log.info("注册世界服务器 {}", mapleWorldServer);

        chmsServerCacheService.save(mapleWorldServer.to(ChmsServer.class, chmsServer -> {
            chmsServer.setType(ChmsServerType.WORLD);
        }));

    }

    @Override
    public void remove(MapleWorldServerDto mapleWorldServer) {
        log.info("移除世界服务器 {}", mapleWorldServer);
    }
}
